package com.tbit.uqbike.client.controller;

import com.tbit.uqbike.client.constant.ResponseCode;
import com.tbit.uqbike.client.exception.BaseException;
import com.tbit.uqbike.client.pojo.vo.RechargeConfigVO;
import com.tbit.uqbike.client.service.GiftCardUserService;
import com.tbit.uqbike.client.service.MachineService;
import com.tbit.uqbike.client.service.RechargeConfigService;
import com.tbit.uqbike.client.service.UserService;
import com.tbit.uqbike.client.util.Assert;
import com.tbit.uqbike.client.util.OutputUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 充值界面
 *
 * @Author: chen
 * @Description: 充值界面
 * @Date: 创建于 13:53 2020/5/8
 */
@RestController
@RequestMapping("/rechargeConfig")
public class RechargeConfigController {
    @Autowired
    private RechargeConfigService rechargeConfigService;
    @Autowired
    private MachineService machineService;
    @Autowired
    private UserService userService;
    @Autowired
    private GiftCardUserService giftCardUserService;

    /**
     * 查询充值自定义界面
     *
     * @param accountId  区域id
     * @param userId     用户id
     * @param orderMoney 订单金额，分
     */
    @RequestMapping("/getByAccountId")
    public void getByAccountId(Integer accountId, HttpSession session, HttpServletRequest request,
                               HttpServletResponse response, Integer userId, @RequestParam(defaultValue = "0") Integer orderMoney) {
        Assert.notNull(accountId, "区域id不能为空", String.valueOf(ResponseCode.FAIL));

        Map<String, Object> map = new HashMap();
        try {
            List<RechargeConfigVO> list = rechargeConfigService.getRechargeInfoByAccountId(accountId,userId, orderMoney);
            map.put(ResponseCode.RET, ResponseCode.SUCC);
            map.put(ResponseCode.DATA, list);
        } catch (BaseException e) {
            ResponseCode.printException(map, e, request);
        }

        OutputUtil.renderText(request, response, map);
    }
}
